package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.limitruleitemvo.LimitRuleItemCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.limitruleitemvo.LimitRuleItemPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.limitruleitemvo.LimitRuleItemRespVO;
import com.cmc.cloud.cmclink.doc.vo.limitruleitemvo.LimitRuleItemUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.LimitRuleItemDO;
import com.cmc.cloud.cmclink.doc.service.LimitRuleItemService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 禁接类明细信息")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/ruleItem")
@Validated
public class LimitRuleItemController {

    @Resource
    private LimitRuleItemService limitRuleItemService;

    @Operation(summary = "创建禁接类明细信息")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission({'doc:maintainBCRDCR:subTable:add','doc:maintainBCRDCR:MatchCondition:add'})")
    public CommonResult<Void> createLimitRuleItem(@Valid @RequestBody LimitRuleItemCreateReqVO createReqVO) {
        limitRuleItemService.createLimitRuleItem(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新禁接类明细信息")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission('doc:maintainBCRDCR:subTable:add')")
    public CommonResult<Void> updateLimitRuleItem(@Valid @RequestBody LimitRuleItemUpdateReqVO updateReqVO) {
        limitRuleItemService.updateLimitRuleItem(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除禁接类明细信息")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission('doc:maintainBCRDCR:MatchCondition:delete')")
    public CommonResult<Void> deleteLimitRuleItem(@PathVariable("id") Long id) {
        limitRuleItemService.deleteLimitRuleItem(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得禁接类明细信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<LimitRuleItemRespVO> getLimitRuleItem(@PathVariable("id") Long id) {
        LimitRuleItemDO limitRuleItem = limitRuleItemService.getLimitRuleItem(id);
        return CommonResult.success(BeanUtil.copyProperties(limitRuleItem, LimitRuleItemRespVO.class));
    }

    @Operation(summary = "从主信息id获得禁接类明细信息")
    @Parameter(name = "mainId", description = "编号", required = true, example = "1024")
    @GetMapping("/getByMainId/{mainId}")
    @UseResponsePropertyAdvice
    public CommonResult<LimitRuleItemRespVO> getByMainId(@PathVariable("mainId") Long mainId) {
        LimitRuleItemRespVO limitRuleItemRespVO = limitRuleItemService.getLimitRuleItemByMainId(mainId);
        return CommonResult.success(limitRuleItemRespVO);
    }

    @Operation(summary = "获得禁接类明细信息列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<LimitRuleItemRespVO>> getLimitRuleItemList(@RequestParam("ids") Collection<Long> ids) {
        List<LimitRuleItemDO> list = limitRuleItemService.getLimitRuleItemList(ids);
        return CommonResult.success(BeanUtil.copyToList(list,LimitRuleItemRespVO.class));
    }

    @Operation(summary = "获得禁接类明细信息分页")
    @UseResponsePropertyAdvice
    @PostMapping("/getPage")
    public CommonResult<PageResult<LimitRuleItemRespVO>> getLimitRuleItemPage(@Valid @RequestBody LimitRuleItemPageReqVO pageVO) {
        PageResult<LimitRuleItemDO> pageResult = limitRuleItemService.getLimitRuleItemPage(pageVO);
        List<LimitRuleItemRespVO> results = BeanUtil.copyToList(pageResult.getList(),LimitRuleItemRespVO.class);
        return CommonResult.success(new PageResult<>(results,pageResult.getTotal()));
    }
}
